<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改库存')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-tInventory-edit" th:object="${tInventory}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
			<input name="deptId"  type="hidden"  th:field="*{deptId}" id="treeId"/>
			<input type="hidden"  th:value="*{variety}" id="varietyId"/>

			<div class="form-group">
				<label class="col-sm-3 control-label">条形码：</label>
				<div class="col-sm-8">
					<input id="barcode" name="barcode" th:field="*{barcode}" class="form-control" type="text" disabled required>
				</div>
			</div>
			<!--<div class="form-group">-->
				<!--<label class="col-sm-3 control-label">饰品名称：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="name" name="name" th:field="*{name}" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<div class="form-group">
				<label class="col-sm-3 control-label">门店：</label>
				<div class="col-sm-8">
					<div class="input-group">
						<input name="deptName" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择归属部门" class="form-control" th:field="*{deptName}" required readonly="true">
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">品类：</label>
				<div class="col-sm-8">
					<select name="category" class="form-control" required>
						<option value="">--请选择品类--</option>
						<option th:each="level : ${category}" th:text="${level.typeName}" th:value="${level.typeId}" th:field="*{category}"></option>
					</select>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">品种：</label>
				<div class="col-sm-8">
					<select id="variety" name="variety" class="form-control" required>
						<option value="">--请选择品种--</option>
					</select>
				</div>
			</div>


			<div class="form-group">	
				<label class="col-sm-3 control-label">重量(g)：</label>
				<div class="col-sm-8">
					<input id="weight" name="weight" th:field="*{weight}" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">标签价格：</label>
				<div class="col-sm-8">
					<input id="labelprice" name="labelprice" th:field="*{labelprice}" class="form-control" type="text" required>
				</div>
			</div>


		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "system/tInventory";
		$("#form-tInventory-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
                var varietyName = $("#variety option:selected").text()
	            $.operate.save(prefix + "/edit", $('#form-tInventory-edit').serialize()+"&name="+varietyName);
	        }
	    }
		/*用户管理-修改-选择部门树*/
		function selectDeptTree() {
			var deptId = $.common.isEmpty($("#treeId").val()) ? "100" : $("#treeId").val();
			var url = ctx + "system/dept/selectDeptTree/" + deptId;
			var options = {
				title: '选择部门',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}

		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowParents(tree)) {
				var body = layer.getChildFrame('body', index);
				$("#treeId").val(body.find('#treeId').val());
				$("#treeName").val(body.find('#treeName').val());
				layer.close(index);
			}
		}

        $("select[name='category']").change(function () {
            var id = $("select[name='category']").val();
            getLevel2(id);
        });

        getLevel2();
		function getLevel2(id) {
		    var id = id == undefined?$("select[name='category']").val():id;
			$.ajax({
				type: "get",
				url: ctx + 'system/types/getLevel2/' + id,
				dataType: "json",
				cache: false, //关闭AJAX缓存
				data: null,
				success: function (data) {
					var levelList = data.data;
					var varietyId = $("#varietyId").val();
					$("select[name='variety']").empty();
					$("select[name='variety']").append("--请选择品种--");
					$.each(levelList, function (i, d) {
						if(d.typeId == varietyId){
                            $("select[name='variety']").append("<option value='" + d.typeId + "' selected='selected'>" + d.typeName + "</option>");
						}else{
                            $("select[name='variety']").append("<option value='" + d.typeId + "'>" + d.typeName + "</option>");
						}
					});
				}
			});
		}
	</script>
</body>
</html>
